﻿Public Class Payment
    Inherits System.Web.UI.Page
    Dim Flight_Number As Integer
    Dim User_Id As Integer
    Dim Price As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        btnContinue.PostBackUrl = "Confirmation.aspx"

        If txtFlightNumber.Value = "" Then
            txtFlightNumber.Value = Request("ctl00$MainContent$txtFlightNumber")

        End If

        If txtUserId.Value = "" Then
            txtUserId.Value = Request("ctl00$MainContent$txtUserId")

        End If
        If txtCost.Value = "" Then
            txtCost.Value = Request("ctl00$MainContent$txtCost")

        End If

        Flight_Number = Convert.ToInt32(txtFlightNumber.Value)
        User_Id = Convert.ToInt32(txtUserId.Value)
        Price = Convert.ToInt32(txtCost.Value)

        totalprice.Text = "$" & Price
        flightnum.Text = Flight_Number
    End Sub

    Function FlightDataSet(ByVal srtSql As String) As DataSet
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand
        Dim dtAdapter As New MySql.Data.MySqlClient.MySqlDataAdapter

        Dim ds As New DataSet

        Dim strConnString

        strConnString = "Server=localhost;User Id=goldair_dapp; Password=geckodev; Database=goldair_db; Pooling=false"


        objConn.ConnectionString = strConnString
        With objCmd
            .Connection = objConn
            .CommandText = srtSql
            .CommandType = CommandType.Text
        End With
        dtAdapter.SelectCommand = objCmd

        Try
            dtAdapter.Fill(ds, "aircraft")
        Catch ex As Exception

        End Try

        dtAdapter = Nothing
        objConn.Close()
        objConn = Nothing

        Return ds

    End Function

    Protected Sub buttonT_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonT.Click
        Dim strMessage
        strMessage = "Payment Processed - Thanks for flying with GoldAir"
        Dim strScript As String = "<script language=JavaScript>"
        strScript += "alert(""" & strMessage & """);"
        strScript += "</script>"

        ExecuteQuery("Update user_flight set payment=1,payment_date='" & Now().ToString("yyyy-MM-dd") & "' where user_id=" & User_Id & " and flight_id=" & Flight_Number)

        If (Not ClientScript.IsStartupScriptRegistered("clientScript")) Then
            ClientScript.RegisterClientScriptBlock(Me.GetType(), "clientScript", strScript)
        End If
    End Sub

    Sub ExecuteQuery(ByVal srtSql As String)
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand
        Dim dtAdapter As New MySql.Data.MySqlClient.MySqlDataAdapter

        Dim ds As New DataSet

        Dim strConnString

        strConnString = "Server=localhost;User Id=goldair_dapp; Password=geckodev; Database=goldair_db; Pooling=false"

        objConn.ConnectionString = strConnString
        objConn.Open()

        With objCmd
            .Connection = objConn
            .CommandText = srtSql
            .CommandType = CommandType.Text
        End With

        objCmd.ExecuteNonQuery()

        objConn.Close()
        objConn = Nothing



    End Sub

End Class